package com.leyou.common.advice;

import com.leyou.common.exceptions.LyException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 注解@{@link ControllerAdvice} 标记当前的类，专门处理SpringMVC中的异常
 * 当controller抛出异常，都交给当前类中的添加了@{@link ExceptionHandler}方法处理
 * @author 虎哥
 */
@ControllerAdvice
public class CommonExceptionAdvice {

    @ExceptionHandler(LyException.class)
    public ResponseEntity<String> handleException(LyException e){
        return ResponseEntity.status(e.getStatus()).body(e.getMessage());
    }
}
